package aerouacmsla.interfazDeUsuario;

import aerouacmsla.procedimientos.BDConexion;
import aerouacmsla.procedimientos.CreateTables;
import java.awt.Component;
import java.awt.print.PrinterException;
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JTable;
import javax.swing.table.DefaultTableColumnModel;
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;
import javax.swing.table.TableModel;
import javax.swing.JOptionPane;

/**
 *
 * @author Marco
 */
public class PanelInformes extends javax.swing.JPanel {

    private BDConexion miConexion;
    private CreateTables modeloTabla = new CreateTables();
    private int opcion;
    private String mensaje;

    public int getOpcion() {
        return opcion;
    }

    public void setOpcion(int opcion) {
        this.opcion = opcion;
    }

    public PanelInformes() {
        initComponents();
        setOpcion(1);
    }

    public PanelInformes(BDConexion miConexion) {
        initComponents();
        setMiConexion(miConexion);
        setOpcion(1);
    }

    public BDConexion getMiConexion() {
        return miConexion;
    }

    public void setMiConexion(BDConexion miConexion) {
        this.miConexion = miConexion;
    }

    public CreateTables getModeloTabla() {
        return modeloTabla;
    }

    public void setModeloTabla(CreateTables modeloTabla) {
        this.modeloTabla = modeloTabla;
    }

    public void setTabla(String SELECT){
        tablaInforme.setModel(getModeloTabla().getTableModel(getMiConexion().sendSQLQuery(SELECT)));
        int vColIndex = 1;
        int margin = 2;
        packColumns(tablaInforme, margin);
    }

    public void packColumns(JTable table, int margin) {
        for (int c=0; c<table.getColumnCount(); c++) {
          packColumn(table, c, 2);
        }
    }

    public void packColumn(JTable table, int vColIndex, int margin) {
        TableModel model = table.getModel();
        DefaultTableColumnModel colModel = (DefaultTableColumnModel)table.
        getColumnModel();
        TableColumn col = colModel.getColumn(vColIndex);
        int width = 0;            // Obtém a largura do cabeçalho da coluna
        TableCellRenderer renderer = col.getHeaderRenderer();
        if (renderer == null) {
            renderer = table.getTableHeader().getDefaultRenderer();
        }
        Component comp = renderer.getTableCellRendererComponent(
            table, col.getHeaderValue(), false, false, 0, 0);
        width = comp.getPreferredSize().width;            // Obtém a largura maxima da coluna de dados
        for (int r=0; r<table.getRowCount(); r++) {
            renderer = table.getCellRenderer(r, vColIndex);
            comp = renderer.getTableCellRendererComponent(
                table, table.getValueAt(r, vColIndex), false, false, r,
                vColIndex);
            width = Math.max(width, comp.getPreferredSize().width);
        }
        width += 2*margin;            // Configura a largura
        col.setPreferredWidth(width);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        panelBotones2 = new javax.swing.JPanel();
        botonImprimir = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        radioButtonFecha = new javax.swing.JRadioButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        radioButtonVuelo = new javax.swing.JRadioButton();
        jLabel4 = new javax.swing.JLabel();
        textFieldVuelo = new javax.swing.JTextField();
        radioButtonOrigenDestino = new javax.swing.JRadioButton();
        jLabel5 = new javax.swing.JLabel();
        textFieldOrigen = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        textFieldDestino = new javax.swing.JTextField();
        radioButtonBoleto = new javax.swing.JRadioButton();
        jLabel7 = new javax.swing.JLabel();
        textFieldBoleto = new javax.swing.JTextField();
        radioButtonAvion = new javax.swing.JRadioButton();
        jLabel8 = new javax.swing.JLabel();
        textFieldAvion = new javax.swing.JTextField();
        radioButtonPasajero = new javax.swing.JRadioButton();
        jLabel9 = new javax.swing.JLabel();
        textFieldPasajero = new javax.swing.JTextField();
        buttonBuscar = new javax.swing.JButton();
        DatePickerFechaInicio = new org.jdesktop.swingx.JXDatePicker();
        DatePickerFechaFin = new org.jdesktop.swingx.JXDatePicker();
        panelTabla2 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        tablaInforme = new org.jdesktop.swingx.JXTable();

        panelBotones2.setBorder(javax.swing.BorderFactory.createTitledBorder("Funciones"));

        botonImprimir.setText("Imprimir Informe");
        botonImprimir.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                botonImprimirMouseClicked(evt);
            }
        });
        botonImprimir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botonImprimirActionPerformed(evt);
            }
        });

        jLabel3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Recursos/IconoReporte32px.png"))); // NOI18N
        jLabel3.setText("Informes");

        buttonGroup1.add(radioButtonFecha);
        radioButtonFecha.setSelected(true);
        radioButtonFecha.setText("Fecha");
        radioButtonFecha.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                radioButtonFechaMouseClicked(evt);
            }
        });

        jLabel1.setText("Fecha inicio:");

        jLabel2.setText("Fecha fin:");

        buttonGroup1.add(radioButtonVuelo);
        radioButtonVuelo.setText("Vuelo");
        radioButtonVuelo.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                radioButtonVueloMouseClicked(evt);
            }
        });

        jLabel4.setText("ID Vuelo:");

        textFieldVuelo.setEditable(false);

        buttonGroup1.add(radioButtonOrigenDestino);
        radioButtonOrigenDestino.setText("Origen y Destino");
        radioButtonOrigenDestino.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                radioButtonOrigenDestinoMouseClicked(evt);
            }
        });

        jLabel5.setText("Origen:");

        textFieldOrigen.setEditable(false);
        textFieldOrigen.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                textFieldOrigenMouseClicked(evt);
            }
        });

        jLabel6.setText("Destino:");

        textFieldDestino.setEditable(false);
        textFieldDestino.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                textFieldDestinoMouseClicked(evt);
            }
        });

        buttonGroup1.add(radioButtonBoleto);
        radioButtonBoleto.setText("Boleto");
        radioButtonBoleto.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                radioButtonBoletoMouseClicked(evt);
            }
        });

        jLabel7.setText("ID Boleto:");

        textFieldBoleto.setEditable(false);

        buttonGroup1.add(radioButtonAvion);
        radioButtonAvion.setText("Avion");
        radioButtonAvion.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                radioButtonAvionMouseClicked(evt);
            }
        });

        jLabel8.setText("ID Avion:");

        textFieldAvion.setEditable(false);

        buttonGroup1.add(radioButtonPasajero);
        radioButtonPasajero.setText("Pasajero");
        radioButtonPasajero.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                radioButtonPasajeroMouseClicked(evt);
            }
        });

        jLabel9.setText("ID");

        textFieldPasajero.setEditable(false);

        buttonBuscar.setText("Buscar");
        buttonBuscar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                buttonBuscarMouseClicked(evt);
            }
        });

        DatePickerFechaInicio.setFormats(new SimpleDateFormat("yyyy-MM-dd"));

        DatePickerFechaFin.setFormats(new SimpleDateFormat("yyyy-MM-dd"));

        javax.swing.GroupLayout panelBotones2Layout = new javax.swing.GroupLayout(panelBotones2);
        panelBotones2.setLayout(panelBotones2Layout);
        panelBotones2Layout.setHorizontalGroup(
            panelBotones2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelBotones2Layout.createSequentialGroup()
                .addGroup(panelBotones2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelBotones2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel3))
                    .addComponent(radioButtonFecha)
                    .addComponent(radioButtonOrigenDestino)
                    .addComponent(radioButtonBoleto)
                    .addComponent(radioButtonAvion)
                    .addComponent(radioButtonPasajero)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelBotones2Layout.createSequentialGroup()
                        .addGap(11, 11, 11)
                        .addGroup(panelBotones2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel6)
                            .addComponent(jLabel5)
                            .addComponent(jLabel7)
                            .addComponent(jLabel8))
                        .addGap(18, 18, 18)
                        .addGroup(panelBotones2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(textFieldAvion)
                            .addComponent(textFieldBoleto)
                            .addComponent(textFieldDestino, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(textFieldOrigen, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE)))
                    .addGroup(panelBotones2Layout.createSequentialGroup()
                        .addGroup(panelBotones2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(panelBotones2Layout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(panelBotones2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel2)
                                    .addComponent(jLabel1)
                                    .addComponent(jLabel4)))
                            .addComponent(radioButtonVuelo))
                        .addGap(18, 18, 18)
                        .addGroup(panelBotones2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(DatePickerFechaFin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(DatePickerFechaInicio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(textFieldVuelo, javax.swing.GroupLayout.DEFAULT_SIZE, 154, Short.MAX_VALUE)))
                    .addGroup(panelBotones2Layout.createSequentialGroup()
                        .addGap(15, 15, 15)
                        .addComponent(jLabel9)
                        .addGap(24, 24, 24)
                        .addComponent(textFieldPasajero, javax.swing.GroupLayout.DEFAULT_SIZE, 191, Short.MAX_VALUE))
                    .addGroup(panelBotones2Layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addGroup(panelBotones2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(buttonBuscar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 221, Short.MAX_VALUE)
                            .addComponent(botonImprimir, javax.swing.GroupLayout.DEFAULT_SIZE, 221, Short.MAX_VALUE))))
                .addContainerGap())
        );
        panelBotones2Layout.setVerticalGroup(
            panelBotones2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelBotones2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(radioButtonFecha)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelBotones2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(DatePickerFechaInicio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelBotones2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(DatePickerFechaFin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(radioButtonVuelo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelBotones2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textFieldVuelo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(radioButtonOrigenDestino)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelBotones2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textFieldOrigen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelBotones2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textFieldDestino, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(radioButtonBoleto)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelBotones2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textFieldBoleto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(radioButtonAvion)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelBotones2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textFieldAvion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8))
                .addGap(3, 3, 3)
                .addComponent(radioButtonPasajero)
                .addGap(8, 8, 8)
                .addGroup(panelBotones2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(textFieldPasajero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 7, Short.MAX_VALUE)
                .addComponent(buttonBuscar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botonImprimir))
        );

        panelTabla2.setBorder(javax.swing.BorderFactory.createTitledBorder("Datos a Imprimir"));

        jScrollPane3.setAutoscrolls(true);

        tablaInforme.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tablaInforme.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        jScrollPane3.setViewportView(tablaInforme);

        javax.swing.GroupLayout panelTabla2Layout = new javax.swing.GroupLayout(panelTabla2);
        panelTabla2.setLayout(panelTabla2Layout);
        panelTabla2Layout.setHorizontalGroup(
            panelTabla2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 441, Short.MAX_VALUE)
        );
        panelTabla2Layout.setVerticalGroup(
            panelTabla2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 457, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(panelBotones2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelTabla2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(panelTabla2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(panelBotones2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void botonImprimirMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_botonImprimirMouseClicked
        //TODO imprimir Tabla
        MessageFormat header = new MessageFormat("Informe " + getMensajeInforme());
        MessageFormat footer = new MessageFormat("-{0}-");
        try {
            tablaInforme.print(JTable.PrintMode.FIT_WIDTH, header, footer);
        } catch (PrinterException ex) {
            Logger.getLogger(PanelInformes.class.getName()).log(Level.SEVERE, null, ex);
        }
}//GEN-LAST:event_botonImprimirMouseClicked

    private void botonImprimirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonImprimirActionPerformed

    }//GEN-LAST:event_botonImprimirActionPerformed

    private void radioButtonFechaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_radioButtonFechaMouseClicked
if(radioButtonFecha.isSelected()){
    limpiar();
    setOpcion(1);
    DatePickerFechaInicio.setEditable(true);
    DatePickerFechaFin.setEditable(true);
    textFieldAvion.setEditable(false);
    textFieldBoleto.setEditable(false);
    textFieldDestino.setEditable(false);
    textFieldOrigen.setEditable(false);
    textFieldPasajero.setEditable(false);
    textFieldVuelo.setEditable(false);
}
    }//GEN-LAST:event_radioButtonFechaMouseClicked

    private void radioButtonVueloMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_radioButtonVueloMouseClicked
if(radioButtonVuelo.isSelected()){
    limpiar();
    setOpcion(2);
    DatePickerFechaInicio.setEditable(false);
    DatePickerFechaFin.setEditable(false);
    textFieldAvion.setEditable(false);
    textFieldBoleto.setEditable(false);
    textFieldDestino.setEditable(false);
    textFieldOrigen.setEditable(false);
    textFieldPasajero.setEditable(false);
    textFieldVuelo.setEditable(true);
        }
    }//GEN-LAST:event_radioButtonVueloMouseClicked

    private void radioButtonOrigenDestinoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_radioButtonOrigenDestinoMouseClicked
if(radioButtonOrigenDestino.isSelected()){
    limpiar();
    setOpcion(3);
    DatePickerFechaInicio.setEditable(false);
    DatePickerFechaFin.setEditable(false);
    textFieldAvion.setEditable(false);
    textFieldBoleto.setEditable(false);
    textFieldDestino.setEditable(true);
    textFieldOrigen.setEditable(true);
    textFieldPasajero.setEditable(false);
    textFieldVuelo.setEditable(false);
        }
    }//GEN-LAST:event_radioButtonOrigenDestinoMouseClicked

    private void radioButtonBoletoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_radioButtonBoletoMouseClicked
if(radioButtonBoleto.isSelected()){
    limpiar();
    setOpcion(4);
    DatePickerFechaInicio.setEditable(false);
    DatePickerFechaFin.setEditable(false);
    textFieldAvion.setEditable(false);
    textFieldBoleto.setEditable(true);
    textFieldDestino.setEditable(false);
    textFieldOrigen.setEditable(false);
    textFieldPasajero.setEditable(false);
    textFieldVuelo.setEditable(false);
        }
    }//GEN-LAST:event_radioButtonBoletoMouseClicked

    private void radioButtonAvionMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_radioButtonAvionMouseClicked
if(radioButtonAvion.isSelected()){
    limpiar();
    setOpcion(5);
    DatePickerFechaInicio.setEditable(false);
    DatePickerFechaFin.setEditable(false);
    textFieldAvion.setEditable(true);
    textFieldBoleto.setEditable(false);
    textFieldDestino.setEditable(false);
    textFieldOrigen.setEditable(false);
    textFieldPasajero.setEditable(false);
    textFieldVuelo.setEditable(false);
        }
    }//GEN-LAST:event_radioButtonAvionMouseClicked

    private void radioButtonPasajeroMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_radioButtonPasajeroMouseClicked
if(radioButtonPasajero.isSelected()){
    limpiar();
    setOpcion(6);
    DatePickerFechaInicio.setEditable(false);
    DatePickerFechaFin.setEditable(false);
    textFieldAvion.setEditable(false);
    textFieldBoleto.setEditable(false);
    textFieldDestino.setEditable(false);
    textFieldOrigen.setEditable(false);
    textFieldPasajero.setEditable(true);
    textFieldVuelo.setEditable(false);
        }
    }//GEN-LAST:event_radioButtonPasajeroMouseClicked

    public void setMensajeInforme(String mensaje){
        this.mensaje = mensaje;
    }
    public String getMensajeInforme(){
        return mensaje;
    }

    private void buttonBuscarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_buttonBuscarMouseClicked
    switch(getOpcion()){
        case 1:
            String fechaInicio;
            String fechaFin;
            fechaInicio=DatePickerFechaInicio.getEditor().getText();
            fechaFin=DatePickerFechaFin.getEditor().getText();
            if(fechaInicio.isEmpty()||fechaFin.isEmpty()){
                JOptionPane.showMessageDialog(null, "tiene que seleccionar dos fechas", "Registro vacio", JOptionPane.ERROR_MESSAGE);
            }else{
                //has la consulta
                setTabla("SELECT id AS 'ID Cliente', nombre AS 'Nombre', telefono AS 'Telefono', fechas AS 'Fecha de Vuelo' FROM informe_fecha WHERE"
                        + " fechas >= '" + fechaInicio + "' AND fechas <= '" + fechaFin + "';");
                setMensajeInforme("Informe por Fechas");
            }
            break;
        case 2:
            setTabla("SELECT id AS 'ID Cliente', nombre AS 'Nombre', telefono AS 'Telefono', id_vuelo AS 'Vuelo' FROM informe_vuelo WHERE id_vuelo = '"
                    + textFieldVuelo.getText() + "';");
            setMensajeInforme("Informe por ID Vuelo");
            break;
        case 3:
            setTabla("SELECT id AS 'ID Cliente', nombre AS 'Nombre', telefono AS 'Telefono', origen AS 'Ciudad Origen', destino AS "
                    + "'Ciudad Destino' FROM informe_origen_destino WHERE origen = '"
                    + textFieldOrigen.getText() + "' AND destino = '" + textFieldDestino.getText() + "';");
            setMensajeInforme("Informe por Origen/Destino");
            break;
        case 4:
            try {
                String numeroBoleto = textFieldBoleto.getText();
                int intentoIntBoleto = Integer.parseInt(numeroBoleto);
                setTabla("SELECT id AS 'ID Cliente', nombre AS 'Nombre', telefono AS 'Telefono', boleto AS 'Numero de Boleto' FROM informe_boleto WHERE"
                        + " boleto =" + intentoIntBoleto + ";");
                setMensajeInforme("Informe por Boleto");
            }
            catch(Exception e){
            }
            break;
        case 5:
            try {
                String numeroAvion = textFieldAvion.getText();
                int intentoIntAvion = Integer.parseInt(numeroAvion);
                setTabla("SELECT id AS 'ID Cliente', nombre AS 'Nombre', telefono AS 'Telefono', id_avion AS 'ID Avion' FROM informe_avion WHERE"
                        + " id_avion =" + intentoIntAvion + ";");
                setMensajeInforme("Informe por Avion");
            }
            catch(Exception e){
            }
            break;
        case 6:
            setTabla("SELECT id AS 'ID Cliente', nombre AS 'Nombre', telefono AS 'Telefono' FROM informe_cliente WHERE id = '"
                    + textFieldPasajero.getText() + "';");
            setMensajeInforme("Informe por ID Clientes");
            break;
    }
    }//GEN-LAST:event_buttonBuscarMouseClicked

    private void textFieldOrigenMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_textFieldOrigenMouseClicked
        DialogoCiudades ciudadOrigen = new DialogoCiudades(getMiConexion());
        ciudadOrigen.setVisible(true);
        String origen = ciudadOrigen.getId();
        textFieldOrigen.setText(origen);
    }//GEN-LAST:event_textFieldOrigenMouseClicked

    private void textFieldDestinoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_textFieldDestinoMouseClicked
        DialogoCiudades ciudadDestino = new DialogoCiudades(getMiConexion());
        ciudadDestino.setVisible(true);
        textFieldDestino.setText(ciudadDestino.getId());
    }//GEN-LAST:event_textFieldDestinoMouseClicked

    public void limpiar(){
        textFieldAvion.setText("");
        textFieldBoleto.setText("");
        textFieldDestino.setText("");
        //textFieldFechaFin.setText("");
        //textFieldFechaInicio.setText("");
        textFieldOrigen.setText("");
        textFieldPasajero.setText("");
        textFieldVuelo.setText("");
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private org.jdesktop.swingx.JXDatePicker DatePickerFechaFin;
    private org.jdesktop.swingx.JXDatePicker DatePickerFechaInicio;
    private javax.swing.JButton botonImprimir;
    private javax.swing.JButton buttonBuscar;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JPanel panelBotones2;
    private javax.swing.JPanel panelTabla2;
    private javax.swing.JRadioButton radioButtonAvion;
    private javax.swing.JRadioButton radioButtonBoleto;
    private javax.swing.JRadioButton radioButtonFecha;
    private javax.swing.JRadioButton radioButtonOrigenDestino;
    private javax.swing.JRadioButton radioButtonPasajero;
    private javax.swing.JRadioButton radioButtonVuelo;
    private javax.swing.JTable tablaInforme;
    private javax.swing.JTextField textFieldAvion;
    private javax.swing.JTextField textFieldBoleto;
    private javax.swing.JTextField textFieldDestino;
    private javax.swing.JTextField textFieldOrigen;
    private javax.swing.JTextField textFieldPasajero;
    private javax.swing.JTextField textFieldVuelo;
    // End of variables declaration//GEN-END:variables

}
